package com.atguigu.educms.service.impl;

import com.atguigu.commonutils.R;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.mapper.CrmBannerMapper;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author hwt
 * @since 2022-09-12
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {


    @Cacheable(value = "banner", key = "'selectIndexList'")
    @Override
    public R getBannerList() {

        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        // 根据排序字段，显示前两条轮播图记录
        wrapper.orderByDesc("sort");
        // 拼接 sql 只查询出两条记录，存在注入风险
        wrapper.last("limit 2");

        List<CrmBanner> list = baseMapper.selectList(wrapper);

        return R.ok().data("list", list);
    }
}
